//
//  MyHeadView.m
//  WBBaseProject
//
//  Created by 吴斌 on 2018/3/6.
//  Copyright © 2018年 吴斌. All rights reserved.
//

#import "MyHeadView.h"
#import "CardBoxView.h"
#import "PersonInfoView.h"

@interface MyHeadView()

@property(strong,nonatomic)UIImageView *blueBg;

@property(strong,nonatomic)UIImageView *whiteBg;
@property(strong,nonatomic)CardBoxView *card1;
@property(strong,nonatomic)CardBoxView *card2;
@property(strong,nonatomic)CardBoxView *card3;
@property(strong,nonatomic)CardBoxView *card4;

@property(strong,nonatomic)PersonInfoView *InfoView;
@end

@implementation MyHeadView


- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
    }
    return self;
}
- (void)layoutSubviews
{
    [self setupUI];
}
- (void)setupUI
{
//    UIView *bg = [[UIView alloc]initWithFrame:self.frame];
//
//    [self addSubview:bg];
    
    //UIImageView *blueBg = [[UIImageView alloc] init];
    self.blueBg.image = WB_ImageName(@"首页蓝色背景");
    //105
    self.blueBg.frame = CGRectMake(0, 0, kScreenWidth, self.mm_height*110/180 + kIPhoneXMoreHeight);
    self.blueBg.userInteractionEnabled = YES;
    [self addSubview:self.blueBg];
    
    // *whiteBg = [[UIImageView alloc] init];
    self.whiteBg.image = WB_ImageName(@"账户中心-矩形背景");
    [self addSubview:self.whiteBg];
    self.whiteBg.userInteractionEnabled = YES;
    self.whiteBg.frame = CGRectMake(15, self.mm_height/2 + kIPhoneXMoreHeight, kScreenWidth - 30, 75);

    //CardBoxView *card1 = [[NSBundle mainBundle] loadNibNamed:@"CardBoxView" owner:self options:nil].firstObject;
    self.card1.titleLb.text = @"我的收藏";
    self.card1.countLb.text = @"33";
    self.card1.frame = CGRectMake(0, 0, self.whiteBg.mm_width / 4, self.whiteBg.mm_height);
    self.card1.tag = 1000;
    [self.whiteBg addSubview:self.card1];
    //给view添加点击手势
    UITapGestureRecognizer *card1Tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(click:)];
    [self.card1 addGestureRecognizer:card1Tap];
    
    //CardBoxView *card2 = [[NSBundle mainBundle] loadNibNamed:@"CardBoxView" owner:self options:nil].firstObject;
    self.card2.titleLb.text = @"银行卡";
    self.card2.countLb.text = @"3";
    self.card2.frame = CGRectMake(self.whiteBg.mm_width / 4, 0, self.whiteBg.mm_width / 4, self.whiteBg.mm_height);
    self.card2.tag = 1001;
    [self.whiteBg addSubview:self.card2];
    //给view添加点击手势
    UITapGestureRecognizer *card2Tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(click:)];
    [self.card2 addGestureRecognizer:card2Tap];
    
    //CardBoxView *card3 = [[NSBundle mainBundle] loadNibNamed:@"CardBoxView" owner:self options:nil].firstObject;
    self.card3.titleLb.text = @"卡卷";
    self.card3.countLb.text = @"2";
    self.card3.frame = CGRectMake(self.whiteBg.mm_width / 4 * 2, 0, self.whiteBg.mm_width / 4, self.whiteBg.mm_height);
    self.card3.tag = 1002;
    [self.whiteBg addSubview:self.card3];
    //给view添加点击手势
    UITapGestureRecognizer *card3Tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(click:)];
    [self.card3 addGestureRecognizer:card3Tap];
    
    //CardBoxView *card4 = [[NSBundle mainBundle] loadNibNamed:@"CardBoxView" owner:self options:nil].firstObject;
    self.card4.titleLb.text = @"钱包";
    self.card4.frame = CGRectMake(self.whiteBg.mm_width / 4 * 3, 0, self.whiteBg.mm_width / 4, self.whiteBg.mm_height);
    self.card4.iconIV.hidden = NO;
    self.card4.tag = 1003;
    [self.whiteBg addSubview:self.card4];
    //给view添加点击手势
    UITapGestureRecognizer *card4Tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(click:)];
    [self.card4 addGestureRecognizer:card4Tap];
    
    //PersonInfoView *InfoView = [[NSBundle mainBundle] loadNibNamed:@"PersonInfoView" owner:self options:nil].firstObject;
    self.InfoView.frame = CGRectMake(0, self.mm_height/2-70, kScreenWidth, 70);
    [self.blueBg addSubview:self.InfoView];
    self.InfoView.headIV.userInteractionEnabled = YES;
    self.InfoView.headIV.tag = 1004;
    //给view添加点击手势
    UITapGestureRecognizer *headTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(click:)];
    [self.InfoView.headIV addGestureRecognizer:headTap];
}

- (void)click:(UITapGestureRecognizer *)tap{
    NSLog(@"哈哈哈哈");
    if (_delegate&&[_delegate respondsToSelector:@selector(myHeadViewClick:withView:)]) {
        [_delegate myHeadViewClick:self withView:tap.view];
    }
}


- (UIImageView *)whiteBg
{
    if (!_whiteBg) {
        _whiteBg = [[UIImageView alloc]init];
    }
    return _whiteBg;
}
- (UIImageView *)blueBg
{
    if (!_blueBg) {
        _blueBg = [[UIImageView alloc]init];
    }
    return _blueBg;
}
- (CardBoxView *)card1
{
    if (!_card1) {
        _card1 = [[NSBundle mainBundle] loadNibNamed:@"CardBoxView" owner:self options:nil].firstObject;
    }
    return _card1;
}
- (CardBoxView *)card2
{
    if (!_card2) {
        _card2 = [[NSBundle mainBundle] loadNibNamed:@"CardBoxView" owner:self options:nil].firstObject;
    }
    return _card2;
}
- (CardBoxView *)card3
{
    if (!_card3) {
        _card3 = [[NSBundle mainBundle] loadNibNamed:@"CardBoxView" owner:self options:nil].firstObject;
    }
    return _card3;
}
- (CardBoxView *)card4
{
    if (!_card4) {
        _card4 = [[NSBundle mainBundle] loadNibNamed:@"CardBoxView" owner:self options:nil].firstObject;
    }
    return _card4;
}
- (PersonInfoView *)InfoView
{
    if (!_InfoView) {
        _InfoView = [[NSBundle mainBundle] loadNibNamed:@"PersonInfoView" owner:self options:nil].firstObject;
    }
    return _InfoView;
}
@end
